import http from '@/api/http'
import type {
    APIResult,
    APIPaging,
    PaginationParams,
    MaterialDTO,
    MaterialQueryParams,
    MaterialCreateParams
} from '@/api/types'

export const materialAPI = {
    // 获取物料列表
    getList: (
        params: PaginationParams & MaterialQueryParams
    ): Promise<APIResult<APIPaging<MaterialDTO>>> => {
        return http.get('/material/list', { params })
    },

    // 获取物料详情
    getDetail: (code: string): Promise<APIResult<MaterialDTO>> => {
        return http.get(`/material/detail/${code}`)
    },

    // 创建物料
    create: (data: MaterialCreateParams): Promise<APIResult<void>> => {
        return http.post('/material/create', data)
    },

    // 更新物料
    update: (
        code: string,
        data: Partial<MaterialCreateParams>
    ): Promise<APIResult<void>> => {
        return http.patch(`/material/update/${code}`, data)
    },

    // 启用/禁用物料
    toggleStatus: (code: string): Promise<APIResult<void>> => {
        return http.post(`/material/toggle-status/${code}`)
    },

    // 物料入库分析
    getStockAnalysis: (): Promise<APIResult<{
        lowStockMaterials: MaterialDTO[]
        expiredMaterials: MaterialDTO[]
    }>> => {
        return http.get('/material/stock-analysis')
    }
}